package com.library.ezd.controller;

import com.library.books.domain.dto.BooksCopyIncrementDto;
import com.library.books.domain.vo.BooksCopyTempVo;
import com.library.common.annotation.RepeatSubmit;
import com.library.common.core.controller.BaseController;
import com.library.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import com.library.ezd.service.core.Ezd30Service;
import org.springframework.web.context.request.async.DeferredResult;

import javax.annotation.Resource;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

/**
 * @Package: PACKAGE_NAME
 * @ClassName: com.library.ezd.controller.Ezd30Controller
 * @Author: Yin
 * @Date: 14:51
 * @Description:
 */
@Api(tags = "ezd30")
@RestController
@RequestMapping("/books/rf")
public class Ezd30Controller extends BaseController {

    @Resource
    Ezd30Service ezd30Service;

    /** 开始扫描RFID并且构建成书籍信息
     *   - 主要是索引号生成
     * */
    @RepeatSubmit(interval = 500 , message = "请稍等")
    @PostMapping("/start")
    public AjaxResult starScan(@RequestBody BooksCopyIncrementDto params) {
        return toAjax(ezd30Service.starScan(params));
//        return toAjax(ezd30Service.starScanTest(params));
    }

    /** 停止扫描RFID构建成书籍信息的执行 */
    @RepeatSubmit(interval = 500 , message = "请稍等")
    @PostMapping("/stop")
    public AjaxResult stopScan() {
        return toAjax(ezd30Service.stopScan());
    }

    /** 执行一个读写器扫描RFID构建书籍的一个周期，指定时间后获得扫描数据
     *   - 开始，获取，延迟，结束
     */
    @RepeatSubmit(interval = 500 , message = "请稍等")
    @PostMapping("/auto")
    public AjaxResult delayScan(@RequestBody BooksCopyIncrementDto params) {
        return success(ezd30Service.autoScan(params));
    }

    /**
     * 开始扫描RFID识别数据
     *  - 将BANK_DATA (TID/EPC) 存在缓存
     */
    @RepeatSubmit(interval = 500 , message = "请稍等")
    @PostMapping("/start/find")
    public AjaxResult starScanRfidBook() {
        return toAjax(ezd30Service.starScanRfidBook());
//        return toAjax(ezd30Service.starScanRfidBookTest());
    }

    /** 停止扫描RFID查找书籍 */
    @RepeatSubmit(interval = 500 , message = "请稍等")
    @PostMapping("/stop/find")
    public AjaxResult stopScanRfidFind() {
        return toAjax(ezd30Service.stopScanRfidBook());
    }

    /** 开始扫描RFID识别书籍副本数据 */
    @RepeatSubmit(interval = 500 , message = "请稍等")
    @PostMapping("/start/fullBook")
    public AjaxResult startScanRfidFindFullCopy() {
        return toAjax(ezd30Service.starScanRfidFullBook());
//        return toAjax(ezd30Service.starScanRfidFullBookTest());
    }

    /**
     * 停止扫描RFID识别书籍副本数据
     *  - 快速打印需要识别RFID得到打印的基本数据（连表数据）存进缓存
     * */
    @RepeatSubmit(interval = 500 , message = "请稍等")
    @PostMapping("/stop/fullBook")
    public AjaxResult stopScanRfidFindFullCopy() {
        return toAjax(ezd30Service.stopScanRfidFullBook());
    }

    /**
     * 获取缓存数据
     *  - 缓存数据是处理过的对象数据列表
     * @param option 有默认选项
     * @return 列表
     */
    @GetMapping("/data/{option}")
    public AjaxResult getData(@PathVariable String option) {
        return success(ezd30Service.data(option));
    }

}
